{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "insured-indication",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "substantial-grace",
   "metadata": {},
   "source": [
    "# 创建数组"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "alone-stroke",
   "metadata": {},
   "source": [
    "## 列表生成数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "worthy-gamma",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = [1, 2, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "antique-consultancy",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.array(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "breeding-bunch",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "modular-virtue",
   "metadata": {},
   "outputs": [],
   "source": [
    "y = [1, 2, 3, 'abc', '甲乙丙']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "adequate-oxygen",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = np.array(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "traditional-marine",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['1', '2', '3', 'abc', '甲乙丙'], dtype='<U11')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cooked-machinery",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1 = [[3,5,7],\n",
    "     [2,4,6]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "hazardous-effectiveness",
   "metadata": {},
   "outputs": [],
   "source": [
    "a1 = np.array(x1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "numerous-eclipse",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 5, 7],\n",
       "       [2, 4, 6]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "civil-syria",
   "metadata": {},
   "outputs": [],
   "source": [
    "x2 = [[3,5],\n",
    "     [2,4,6]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "nominated-security",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-13-6ecb1ef1e58f>:1: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
      "  a2 = np.array(x2)\n"
     ]
    }
   ],
   "source": [
    "a2 = np.array(x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "excessive-fundamental",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([list([3, 5]), list([2, 4, 6])], dtype=object)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "answering-appliance",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 即将不被允许，需要制定dtype，整整齐齐，不能缺失"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "overhead-latter",
   "metadata": {},
   "source": [
    "## 函数生成规律数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "close-congress",
   "metadata": {},
   "outputs": [],
   "source": [
    "c = np.zeros(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "alert-permit",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "advisory-parliament",
   "metadata": {},
   "outputs": [],
   "source": [
    "c = np.zeros(10, dtype='int')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "danish-hollow",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "sufficient-marathon",
   "metadata": {},
   "outputs": [],
   "source": [
    "d = np.zeros((3,4), dtype='int')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "atlantic-cache",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0],\n",
       "       [0, 0, 0, 0],\n",
       "       [0, 0, 0, 0]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "prompt-milan",
   "metadata": {},
   "outputs": [],
   "source": [
    "e = np.ones((3,4), dtype=\"int\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "upper-deposit",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 1],\n",
       "       [1, 1, 1, 1],\n",
       "       [1, 1, 1, 1]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cutting-intranet",
   "metadata": {},
   "outputs": [],
   "source": [
    "eye1 = np.eye(6, dtype='int')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "restricted-belgium",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 0, 0, 0, 0, 0],\n",
       "       [0, 1, 0, 0, 0, 0],\n",
       "       [0, 0, 1, 0, 0, 0],\n",
       "       [0, 0, 0, 1, 0, 0],\n",
       "       [0, 0, 0, 0, 1, 0],\n",
       "       [0, 0, 0, 0, 0, 1]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eye1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "unique-commercial",
   "metadata": {},
   "outputs": [],
   "source": [
    "f = np.arange(1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "arbitrary-gardening",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cooperative-image",
   "metadata": {},
   "outputs": [],
   "source": [
    "g = np.arange(1, 100, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "attached-california",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  4,  7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49,\n",
       "       52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "hybrid-paradise",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 步长可以为小数，优于range\n",
    "h = np.arange(1, 20, 0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "premier-confidence",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5,  5. ,  5.5,  6. ,\n",
       "        6.5,  7. ,  7.5,  8. ,  8.5,  9. ,  9.5, 10. , 10.5, 11. , 11.5,\n",
       "       12. , 12.5, 13. , 13.5, 14. , 14.5, 15. , 15.5, 16. , 16.5, 17. ,\n",
       "       17.5, 18. , 18.5, 19. , 19.5])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "incoming-chorus",
   "metadata": {},
   "outputs": [],
   "source": [
    "i = np.arange(1, -11.1, -3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "great-honor",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  1.,  -2.,  -5.,  -8., -11.])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "responsible-plate",
   "metadata": {},
   "source": [
    "## 生成随机数组"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "expired-exploration",
   "metadata": {},
   "source": [
    "### np.random.rand()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "hispanic-turning",
   "metadata": {},
   "outputs": [],
   "source": [
    "j = np.random.rand(3, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "convinced-positive",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.16938325, 0.64901025, 0.65517501, 0.93752023, 0.0187533 ],\n",
       "       [0.5957487 , 0.69149234, 0.87074256, 0.28066513, 0.66530201],\n",
       "       [0.74235142, 0.7342706 , 0.35154576, 0.02778274, 0.44852886]])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "stretch-wheat",
   "metadata": {},
   "outputs": [],
   "source": [
    "k = np.random.rand(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "consistent-fraction",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.58019096, 0.97457289, 0.01810263])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "cooperative-collins",
   "metadata": {},
   "outputs": [],
   "source": [
    "l = np.random.rand(3,4,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "sunrise-thomson",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[0.80202638, 0.30777385, 0.34378756, 0.57505794, 0.44275283],\n",
       "        [0.42927997, 0.90330856, 0.12220944, 0.21755088, 0.19717512],\n",
       "        [0.09767461, 0.53922611, 0.53666564, 0.66925316, 0.58408179],\n",
       "        [0.32959802, 0.2940293 , 0.80772913, 0.38853932, 0.26791876]],\n",
       "\n",
       "       [[0.73860634, 0.90993296, 0.43006622, 0.64390561, 0.31322212],\n",
       "        [0.19315588, 0.7405331 , 0.66777822, 0.55193845, 0.15969792],\n",
       "        [0.81204947, 0.16434847, 0.25524213, 0.06710383, 0.13010142],\n",
       "        [0.68157781, 0.65378004, 0.31740246, 0.96731391, 0.68088498]],\n",
       "\n",
       "       [[0.35467231, 0.07820265, 0.75485378, 0.93063886, 0.42814506],\n",
       "        [0.39458878, 0.47914104, 0.55958558, 0.85248701, 0.66693721],\n",
       "        [0.75661523, 0.60001163, 0.78022175, 0.49870466, 0.50085057],\n",
       "        [0.46509705, 0.97081826, 0.73925941, 0.00847934, 0.71282605]]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acute-flesh",
   "metadata": {},
   "source": [
    "### numpy.random.randint()\n",
    "随机整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "fuzzy-happening",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = np.random.randint(-10, 10, (3,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "proved-commitment",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ -7,  -4,  -7,  -1,  -1],\n",
       "       [  4,  -2,   2, -10,   4],\n",
       "       [ -9,   8,   8,   6,   5]])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "purple-moment",
   "metadata": {},
   "source": [
    "### numpy.random.choice()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "indonesian-turtle",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = np.random.choice(['星期一', '星期二', '星期三', '星期四', '星期五'], (3, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "arabic-spectrum",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['星期四', '星期五', '星期五', '星期四', '星期二'],\n",
       "       ['星期三', '星期五', '星期三', '星期五', '星期四'],\n",
       "       ['星期五', '星期二', '星期三', '星期五', '星期五']], dtype='<U3')"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "judicial-plaintiff",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 读取文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "responsible-porcelain",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_file = np.loadtxt(r'D:\\Programming\\Python\\PlayTogether_Data\\book2_np\\data01.txt', delimiter=',', dtype='int')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "humanitarian-publication",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   1,    2,   32,   43,   12,   32,   12,   32],\n",
       "       [   8,   23,   23,   43,   90,    4,    2,   29],\n",
       "       [  98,    3,    4,   24,   24,  132,  809, 1024]])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "substantial-keyboard",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "could not convert string to float: ''",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-71-78185627a8ff>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdata_file02\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloadtxt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mr'D:\\Programming\\Python\\PlayTogether_Data\\book2_np\\data02.txt'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdelimiter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m','\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'int'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32me:\\program files\\python38\\lib\\site-packages\\numpy\\lib\\npyio.py\u001b[0m in \u001b[0;36mloadtxt\u001b[1;34m(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows, like)\u001b[0m\n\u001b[0;32m   1144\u001b[0m         \u001b[1;31m# converting the data\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1145\u001b[0m         \u001b[0mX\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1146\u001b[1;33m         \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mread_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_loadtxt_chunksize\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1147\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mX\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1148\u001b[0m                 \u001b[0mX\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32me:\\program files\\python38\\lib\\site-packages\\numpy\\lib\\npyio.py\u001b[0m in \u001b[0;36mread_data\u001b[1;34m(chunk_size)\u001b[0m\n\u001b[0;32m    995\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    996\u001b[0m             \u001b[1;31m# Convert each value according to its column and store\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 997\u001b[1;33m             \u001b[0mitems\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mconv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mconv\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mconverters\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    998\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    999\u001b[0m             \u001b[1;31m# Then pack it according to the dtype's nesting\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32me:\\program files\\python38\\lib\\site-packages\\numpy\\lib\\npyio.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m    995\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    996\u001b[0m             \u001b[1;31m# Convert each value according to its column and store\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 997\u001b[1;33m             \u001b[0mitems\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mconv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mconv\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mconverters\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    998\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    999\u001b[0m             \u001b[1;31m# Then pack it according to the dtype's nesting\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32me:\\program files\\python38\\lib\\site-packages\\numpy\\lib\\npyio.py\u001b[0m in \u001b[0;36m<lambda>\u001b[1;34m(x)\u001b[0m\n\u001b[0;32m    742\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mint64\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    743\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0missubclass\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtyp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minteger\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 744\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    745\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0missubclass\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtyp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlongdouble\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    746\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlongdouble\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: could not convert string to float: ''"
     ]
    }
   ],
   "source": [
    "data_file02 = np.loadtxt(r'D:\\Programming\\Python\\PlayTogether_Data\\book2_np\\data02.txt', delimiter=',', dtype='int')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "consolidated-background",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据缺失的数据补充方法：\n",
    "data_file02 = np.genfromtxt(r'D:\\Programming\\Python\\PlayTogether_Data\\book2_np\\data02.txt', delimiter=',', dtype='int', \n",
    "                            filling_values=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "coastal-pontiac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   1,    2,   32,   43,    0,    0,   12,   32],\n",
       "       [   8,   23,    0,   43,   90,    4,    2,   29],\n",
       "       [  98,    3,    4,   24,   24,  132,    0, 1024]])"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_file02"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
